package com.he.service;

import com.he.DesignPatterns.iterator.Student;
import com.he.mapper.StuMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @description: TODO
 * @Author: HCL
 * @Date: 2024/11/25 8:57
 */
@Service
public class StuServiceImpl implements StuService {
    @Resource
    private StuMapper stuMapper;

    @Override
    public void insertStu(Student student) {
        stuMapper.insert(student);
    }


    public void deduplicateEntities() {
        List<Student> entities = stuMapper.selectList(null);
        Set<Integer> uniqueFields = new HashSet<>();
        List<Long> idsToDelete = new ArrayList<>();
        // 遍历记录列表，找出重复的记录ID
        for (Student entity : entities) {
            if (!uniqueFields.add(entity.getSId())) {
                idsToDelete.add(entity.getId());
            }
        }
       stuMapper.deleteBatchIds(idsToDelete);


    }
}
